/*************************************************************/
//2014.03.06修改版
/*************************************************************/
#include <string.h>
#include "fm175xx.h"
#include "FM17550Register.h"
#include "BSP.h"
#include "BSP_Delay.h"
#include "contactless.h"
#include <WCI.h>
#include <WCIPrivate.h>
#include "Fifo.h"
#include "CardMemPrivate.h"

//#include "CardMifare.h"
#include <Card.h>
#include <CardPort.h>
#include <CardPortPrivate.h>

typedef struct RegisterTag{
	uint8_t address;
	uint8_t valude;
}Register_T;


static unsigned char Read_Reg(unsigned char reg_add) {
    return RFIO_Read(reg_add);
}

static unsigned char Read_Reg_All(unsigned char *reg_value) {
    unsigned char  i;
    for (i=0; i<64; i++){
		reg_value[i] = RFIO_Read(i);
	}
    return WCI_S_OK;
}
/*************************************************************/
/*函数名：	    Write_Reg				         */
/*功能：	    写寄存器操作				 */
/*								 */
/*输入参数：	reg_add，寄存器地址；reg_value，寄存器数值	 */
/*返回值：	    WCI_S_OK						 */
/*				WCI_S_Hardware				 */
/*************************************************************/
static unsigned char Write_Reg(unsigned char reg_add,unsigned char reg_value) {
	RFIO_Write(reg_add, reg_value);
    return WCI_S_OK;
}

/*************************************************************/
/*函数名：	    Set_BitMask									 */
/*功能：	    置位寄存器操作								 */
/*输入参数：	reg_add，寄存器地址；mask，寄存器置位		 */
/*返回值：	    WCI_S_OK											 */
/*				WCI_S_Hardware										 */
/*************************************************************/
static unsigned char Set_BitMask(unsigned char reg_add,unsigned char mask) {
    unsigned char result;
    unsigned char val = Read_Reg(reg_add) | mask;
    result=Write_Reg(reg_add, val);  // set bit mask
    return result;
}

/*   C L E A R _   B I T   M A S K   */
/*-------------------------------------------------------------------------
    清零寄存器位操作
-------------------------------------------------------------------------*/
static unsigned char Clear_BitMask(unsigned char reg_add,unsigned char mask) {
    unsigned char  result;
    unsigned char val = Read_Reg(reg_add) & ~mask;
    result=Write_Reg(reg_add, val);  // clear bit mask
    return result;
}



/*************************************************************/
/*函数名：	    Read_FIFO									 */
/*功能：	    读取FIFO  									 */
/*															 */
/*输入参数：	length，读取数据长度						 */
/*输出参数：	*fifo_data，数据存放指针					 */
/*返回值：	    											 */
/*															 */
/*************************************************************/
static void Read_FIFO(unsigned char length,unsigned char *fifo_data) {
	RFIO_ReadSequence(FIFODataReg, fifo_data, length);
}
/*************************************************************/
/*函数名：	    Write_FIFO									 */
/*功能：	    写入FIFO  									 */
/*															 */
/*输入参数：	length，读取数据长度；*fifo_data，数据存放指针*/
/*输出参数：												 */
/*返回值：	    											 */
/*															 */
/*************************************************************/
static void Write_FIFO(unsigned char length,unsigned char *fifo_data) {
	RFIO_WriteSequence(FIFODataReg, fifo_data, length);
}
/*************************************************************/
/*函数名：	    Clear_FIFO									 */
/*功能：	    清空FIFO  									 */
/*															 */
/*输入参数：	无											*/
/*输出参数：												 */
/*返回值：	    WCI_S_OK											 */
/*				WCI_S_Hardware										 */
/*************************************************************/
static unsigned char Clear_FIFO(void) {
    Set_BitMask(FIFOLevelReg,0x80);//清除FIFO缓冲
    if (RFIO_Read(FIFOLevelReg)==0)
        return WCI_S_OK;
    else
        return WCI_S_Hardware;
}

/*
Type A 默认配置表
*/
static const Register_T fm17ConfigTypeA[] = {
	{ControlReg, 0x10}, // 设置reader模式

	{BitFramingReg, 0x00},
	{ModeReg, 0x3D},			//CRCPreset = 6363H
	{RxSelReg, 0x88},
	{TxAutoReg, 0x40},
	{RFCfgReg, 0x78},
	{GsNOnReg, 0xFC},
	{GsNOffReg, 0x88},
	{CWGsPReg, 0x3F},						//0x20
	{MfRxReg, 0x00},
	{DemodReg, 0x42},
	{TxModeReg, 0x80},  //TxModeReg 0x12 设置TX CRC有效，TX FRAMING =TYPE A
	{RxModeReg, 0x80}, //RxModeReg 0x13 设置RX CRC有效，RX FRAMING =TYPE A
	{RxThresholdReg, 0x75},  // 0x18寄存器
	
	{ModWidthReg, 0x26},
	{MaxReg, 0x00},
};

/*
Type B 默认配置表
*/

static const Register_T fm17ConfigTypeB[] = {
	{ControlReg, 0x10}, //ControlReg 0x0C 设置reader模式
	
	{ModeReg, 0x3F},
	{BitFramingReg, 0x00},
	{RFCfgReg, 0x78},
	{GsNOnReg, 0xFF}, //GsNReg 0x27 设置ON电导
	{GsNOffReg, 0xF4}, //GsNOffReg 0x23 设置OFF电导
	{CWGsPReg, 0x3F},	
	{MfRxReg, 0x10},
	{TxAutoReg, 0x00},// TxASKReg 0x15 设置100%ASK无效
	{TypeBReg, 0x00},
	{DemodReg, 0x42},
	
	{TxModeReg, 0x83}, //TxModeReg 0x12 设置TX CRC有效，TX FRAMING =TYPE B
	{RxModeReg, 0x83}, //RxModeReg 0x13 设置RX CRC有效，RX FRAMING =TYPE B
	{RxThresholdReg, 0x75},
	
//		{ModGsPReg, 0x2C},
	{ModGsPReg, 0x1E},
	{MaxReg, 0x00},
};

/*
FiliCa 默认配置表
*/

static const Register_T fm17ConfigTypeF[] = {
	{ControlReg, 0x10}, //ControlReg 0x0C 设置reader模式
	{TxModeReg, 0x92}, //TxModeReg 0x12 设置TX CRC有效，212kbps,TX FRAMING =Felica
	{RxModeReg, 0x96}, //RxModeReg 0x13 设置RX CRC有效，212kbps,Rx Multiple Enable,RX FRAMING =Felica
	{GsNOnReg, 0xF4}, //GsNReg 0x27 设置ON电导
	{CWGsPReg, 0x20}, //
	{GsNOffReg, 0x4F}, //GsNOffReg 0x23 设置OFF电导
	{ModGsPReg, 0x20},
	{TxAutoReg, 0x07},// TxASKReg 0x15 设置100%ASK无效
	{MaxReg, 0x00},
};

static const Register_T * fm17ConfigTable[3] = {
	fm17ConfigTypeA,
	fm17ConfigTypeB,
	fm17ConfigTypeF
};


static volatile unsigned char RegVal;

/*   F   M 1 7 _   S E T   C O N F I G   */
/*-------------------------------------------------------------------------
    将配置表写入FM17
-------------------------------------------------------------------------*/
static void FM17_SetConfig(const Register_T* configs){
	const Register_T* reg = configs;
	
	while(reg->address < MaxReg){
		Write_Reg(reg->address, reg->valude);
		reg++;
	}
}

unsigned char Set_Rf(unsigned char mode) {

	if(mode){
		Write_Reg(TxControlReg, 0x83);
	}
	else{
		Write_Reg(TxControlReg, 0x00);
	}
	return 0;
}

/*
WS1850 的定时器时钟频率为6.78MHz ，
在此，我们按13.56MHz计算 ，因此时间等待时间增加了一倍。
*/
static void FM17_SetWaitTime(uint32_t fc) {
    /*
    	Time = (Prescaler * 2 + 1) * Reload + 1
    	Reload 越大计时越精确
    */
    uint8_t RegTmode;
    uint32_t Prescale;
    uint32_t Counter;
    uint32_t CountUnit;
    uint32_t Time;

    if(fc != 0) {
        Time = fc - 1;
    } else {
        Time = 0;
    }

    Prescale = Time / 0xFFFF;

    if((Time & 0xFFFF) != 0) { //余数不为0
        Prescale++;
    }

    Prescale /= 2;

    CountUnit = 2 * Prescale + 1;
    Counter = Time / CountUnit;

    if((Time % CountUnit) != 0) { //余数不为0
        Counter++;
    }

    if(Prescale > 4095) {
        Counter = 65535;
        Prescale = 4095;
    }

    RegTmode = Read_Reg(TModeReg);
    RegTmode &= 0xF0;
    RegTmode |= ((Prescale >> 8) & 0x0F);
    Write_Reg(TModeReg, RegTmode);
    
    Write_Reg(TPrescalerReg, Prescale & 0xFF);
    Write_Reg(TReloadMSBReg, (Counter >> 8) & 0xFF);
    Write_Reg(TReloadLSBReg, Counter & 0xFF);

}

static void FM17_SetTimerMode(uint8_t Mode) {
    uint8_t RegTmode = Read_Reg(REG_TMODE);

    RegTmode &= 0x0F;
    RegTmode |= Mode & 0xF0;
    Write_Reg(TModeReg, RegTmode);
}


static void FM17_StartTimer(void) {
    Set_BitMask(ControlReg, BFL_JBIT_TSTARTNOW);    
}


static void FM17_StopTimer(void) {
    Set_BitMask(ControlReg, BFL_JBIT_TSTOPNOW);
}

static int FM17_CheckTimeout(void){
	int irq = Read_Reg(ComIrqReg);//查询中断标志
	return (irq & 0x01) != 0;
}

void Delay_Fc(unsigned int fc){
	unsigned int loop = 5000 / 4; // 4 us per loop, max wait 5ms.
	
	FM17_SetTimerMode(0); //计数器减至0，irq置位
	FM17_SetWaitTime(fc);
	FM17_StartTimer();
	while(!FM17_CheckTimeout()){ 
		if(--loop == 0){
			break;
		}
	}
	FM17_StopTimer();
}


unsigned char Pcd_ConfigISOType(unsigned char type) {

	if(type < 3){
		FM17_SetConfig(fm17ConfigTable[type]);
		return WCI_S_OK;
	}
	return WCI_S_Hardware;
}


/*   F   M 1 7 5   X   X _   S O F T   R E S E T   */
/*-------------------------------------------------------------------------
    FM175XX 软复位
-------------------------------------------------------------------------*/
unsigned char  FM175XX_SoftReset(void) {
    Write_Reg(CommandReg,SoftReset);//

    while(Read_Reg(CommandReg)==SoftReset);
    return WCI_S_OK;

}

unsigned char FM175XX_HardReset(void) {
    RFIO_SetReset(0);
    BSP_Delay_ms(10);
    RFIO_SetReset(1);
    BSP_Delay_ms(10);
    return WCI_S_OK;
}

unsigned char FM175XX_SoftPowerdown(void) {
    if (Read_Reg(CommandReg)&0x10) {
        Clear_BitMask(CommandReg,0x10);//退出低功耗模式
        return WCI_S_Hardware;
    } else
        Set_BitMask(CommandReg,0x10);//进入低功耗模式
    return WCI_S_OK;
}


unsigned char FM175XX_HardPowerdown(unsigned char mode) {	
    RFIO_SetReset(0);
    return WCI_S_OK;

}

static int FM175xx_SetMode(WCI* wci, int mode){
#if 0
	if(wci->mode == mode){
		return 0;
	}
#endif 
	mode &= ~ WCI_ForceMark;
	switch(mode){
	case WCI_Mode_A:
	case WCI_Mode_B:{
		FM17_SetConfig(fm17ConfigTable[mode]);
	}
	break;
	default :
		return -1;
	}
	wci->mode = mode;
	BSP_Delay_ms(1);
	return 0;
}



static int FM175xx_Config(WCI* wci, int cfg){
#if 0
	if(wci->config == cfg){
		return 0;
	}
#endif 
	cfg &= ~ WCI_ForceMark;
	switch(cfg){
	case WCI_Cfg_Short:{		
		Clear_BitMask(ModeReg, 0x40);
		Clear_BitMask(TxModeReg,0x80); //关闭TX CRC
		Clear_BitMask(RxModeReg,0x80); //关闭RX CRC

		Clear_BitMask(Status2Reg,0x08); //关闭加密
//		Write_Reg(CollReg,0x80);//冲突位后的接收数据不改变
		Write_Reg(BitFramingReg,0x07);
	}
	break;

	case WCI_Cfg_Anti:{
		Clear_BitMask(TxModeReg,0x80); //关闭TX CRC, 106 kbps, Type A帧格式
		Clear_BitMask(RxModeReg,0x80); //关闭RX CRC, 106 kbps, Type A帧格式
		Write_Reg(CollReg,0x00);//冲突位后的接收数据为0
	}
	break;
	
	case WCI_Cfg_Sel:{		
		Write_Reg(TxModeReg,0x80); //打开TX CRC, 106 kbps, Type A帧格式，CRC初始值自动选择
		Write_Reg(RxModeReg,0x80); //打开RX CRC, 106 kbps, Type A帧格式，CRC初始值自动选择
		Write_Reg(BitFramingReg,0x00);
	}
	break;

	case WCI_Cfg_RATS:{
		Write_Reg(TxModeReg,0x80); //打开TX CRC, 106 kbps, Type A帧格式，CRC初始值自动选择
		Write_Reg(RxModeReg,0x80); //打开RX CRC, 106 kbps, Type A帧格式，CRC初始值自动选择
		Write_Reg(BitFramingReg,0x00);
	}
	break;
	
	case WCI_Cfg_HaltA:{
		Write_Reg(TxModeReg,0x80); //打开TX CRC, 106 kbps, Type A帧格式，CRC初始值自动选择
		Write_Reg(RxModeReg,0x80); //打开RX CRC, 106 kbps, Type A帧格式，CRC初始值自动选择
		Write_Reg(BitFramingReg,0x00);
	}
	break;

	case WCI_Cfg_ExchangeA:{
		Write_Reg(TxModeReg,0x80); //打开TX CRC, 106 kbps, Type A帧格式，CRC初始值自动选择
		Write_Reg(RxModeReg,0x80); //打开RX CRC, 106 kbps, Type A帧格式，CRC初始值自动选择
		Write_Reg(BitFramingReg,0x00);
	}
	break;

	case WCI_Cfg_RfOn:{
		Set_Rf(1);
	}
	break;
	case WCI_Cfg_RfOff:{
		Set_Rf(0);
	}
	break;
	default:
		return -1;
	}
#if 0
	wci->config = cfg;
#endif 
	BSP_Delay_ms(1);
	return 0;
}

int FM175xx_Aligned(WCI* wci, unsigned int txBits, unsigned int rxPos){
	unsigned char val = rxPos << 4 | txBits;
	val &= 0x7F;
	Write_Reg(BitFramingReg, val);
    return 0;
}



//fill chip FIFO full or no more data
static int FM175xx_WriteBuffer(WCI* wci){
	unsigned int i;
	unsigned int length = WCI_FifoLength(wci);
	unsigned int space = 64 - Read_Reg(FIFOLevelReg);
	unsigned int wlen = length > space ? space : length;
	uint8_t ch;	
	
	for(i = 0; i < wlen; ++i){
		if(WCI_ReadFifo(wci, &ch, 1)){
			Write_FIFO(1, &ch);
		}
		else{
			break;
		}
	}
	return i;
}

static int FM175xx_ReadBuffer(WCI* wci){
	unsigned int i;
	unsigned int space = WCI_FifoSpace(wci);
	unsigned int level = Read_Reg(FIFOLevelReg);
	unsigned int rlen = space > level ? level : space;
	uint8_t ch;	
	
	for(i = 0; i < rlen; ++i){
		Read_FIFO(1, &ch);
		if(!WCI_WriteFifo(wci, &ch, 1)){
			break;
		}
	}
	return i;
}

static int FM175xx_Authen(WCI* wci, uint8_t cmd, WciTime_T* time, void* param){	
	unsigned char irq;
	int result;
	MfAuthParam_T* mfauth = (MfAuthParam_T*)param;
	uint8_t txBuf[16];
	uint8_t tlen = 0;
    if(Clear_FIFO() != WCI_S_OK){
		return WCI_S_Unknow;
    }

	txBuf[tlen++] = mfauth->keyType;
	txBuf[tlen++] = mfauth->block;
	memcpy(&txBuf[tlen], mfauth->keys, sizeof(mfauth->keys));
	tlen += sizeof(mfauth->keys);
	memcpy(&txBuf[tlen], mfauth->uid, sizeof(mfauth->uid));
	tlen += sizeof(mfauth->uid);
	
    FM17_SetWaitTime(time->waitTime);
    Write_Reg(WaterLevelReg,0x20);//设置FIFOLevel=32字节
    Write_Reg(ComIrqReg,0x7F);//清除IRQ标志

	Write_FIFO(tlen, txBuf);
    Write_Reg(CommandReg, MFAuthent);
	Set_BitMask(BitFramingReg, 0x80);//启动发送
    Set_BitMask(TModeReg,0x80);//自动启动定时器

    while(1) { //循环判断中断标识
		irq = Read_Reg(ComIrqReg);//查询中断标志

		if(irq&0x10)	//IdelIRq  command寄存器为空闲，指令操作完成
		{
			result = WCI_S_OK;
			break;
		}
		if(irq&0x01) {	//TimerIRq  定时器时间用尽
		    result = WCI_S_Timeout;
		    break;
		}
		if((Read_Reg(TxControlReg) & 0x03) == 0){
			result = WCI_S_Unknow;
			break;
		}
	}
	if(result == WCI_S_OK){
		//判断加密标志位，确认认证结果
		if((Read_Reg(Status2Reg) & 0x08) == 0){
			result = WCI_S_Protocol;
		}
	}
    Set_BitMask(ControlReg,0x80);     // stop timer now
    Write_Reg(CommandReg,Idle);
    Clear_BitMask(BitFramingReg,0x80);//关闭发送
	return result;
}

static int FM175xx_CmdExchange(WCI* wci, uint8_t cmd, WciTime_T* time, void* param){
    unsigned char  result;
    unsigned char  rx_temp=0;//临时数据字节长度
    unsigned char  rx_len=0;//接收数据字节长度
    unsigned char  lastBits=0;//接收数据位长度
    unsigned char  irq;
	uint8_t tlen = WCI_FifoLength(wci);
	uint8_t level = 48;
	WciBits_T* bits = (WciBits_T*) param;
	int ret;
	
    Delay_Fc(time->guardTime);
    FM17_SetWaitTime(time->waitTime);
    Write_Reg(WaterLevelReg,level);//设置FIFOLevel=48字节
    Write_Reg(ComIrqReg,0x7F);//清除IRQ标志
    Set_BitMask(TModeReg,0x80);//自动启动定时器
	FM175xx_Aligned(wci, bits->lastTx, bits->lastRx);
	ret = FM175xx_WriteBuffer(wci);
	tlen -= ret;
    Write_Reg(CommandReg,Transceive);
	Set_BitMask(BitFramingReg,0x80);//启动发送

    while(1) { //循环判断中断标识
        irq = Read_Reg(ComIrqReg);//查询中断标志

		if((irq&0x04)&&(tlen>0)) { //LoAlertIrq + 发送字节数大于0
			ret = FM175xx_WriteBuffer(wci);
			tlen -= ret;
			Write_Reg(ComIrqReg,0x04);//清除LoAlertIrq
		}
		if(irq&0x08) {	//HiAlertIRq
			if((irq&0x40)&&(tlen==0)) { //TxIRq	+ 待发送长度为0 + FIFO长度大于32
				ret = FM175xx_ReadBuffer(wci);
				rx_len += ret;
			}
		}
		if((irq&0x20)&&(tlen==0)) {	//RxIRq=1
#if 0
			if(Read_Reg(Status2Reg) < 2){
				result=WCI_S_OK;
				break;
			}
#endif 
			result=WCI_S_OK;
			break;
		}
		if(irq&0x01) {	//TimerIRq  定时器时间用尽
            result=WCI_S_Timeout;
            break;
        }
		if((Read_Reg(TxControlReg) & 0x03) == 0){
			result = WCI_S_Unknow;
			break;
		}
    }

	if(result == WCI_S_OK){ // read data in FIFO
		rx_temp=Read_Reg(FIFOLevelReg);
		lastBits = Read_Reg(ControlReg) & 0x07;
		bits->lastRx = lastBits;
		if ((rx_temp==0)&&(lastBits>0))	{
		//如果收到长度未满1个字节，则设置接收长度为1个字节
			uint8_t ch;
			
			rx_temp=1;
			Read_FIFO(1, &ch);
			WCI_WriteFifo(wci, &ch, 1);
		}
		else{
			FM175xx_ReadBuffer(wci);
		}
	}	

    if(result == WCI_S_OK){ // check errors
        unsigned char err = Read_Reg(ErrorReg);
        if(err & BFL_JBIT_COLLERR){
			result = WCI_S_Coll;
        }
		else
		if(err & BFL_JBIT_CRCERR){
			result = WCI_S_Crc;
		}
        else
		if(err & BFL_JBIT_PARITYERR){
			result = WCI_S_Parity;
		}
        else
        if(err){
			result = WCI_S_Hardware;
        }
    }

    Set_BitMask(ControlReg,0x80);     // stop timer now
    Write_Reg(CommandReg,Idle);
    Clear_BitMask(BitFramingReg,0x80);//关闭发送
	Clear_FIFO();
    return result;
}

int FM175xx_Command(WCI* wci, uint8_t cmd, WciTime_T* time, void* param){
	if(cmd == WCI_Cmd_Exchagne){
		return FM175xx_CmdExchange(wci, cmd, time, param);
	}
	if(cmd == WCI_Cmd_Authen){
		return FM175xx_Authen(wci, cmd, time, param);
	}
	return -1;
}


static const WCIOps opsFM17550 = {
	.setMode = FM175xx_SetMode,
	.config = FM175xx_Config,
	.command = FM175xx_Command,
};


WCI wciFM17550 = {
	.ops = &opsFM17550,
	.name = "FM17550",
	.support = 0x03,
	.mode = -1,
	.config = -1,
};


#if 0
static uint8_t FM175xx_Check(void){
#if 1
	uint8_t buf = 0xAA;
	uint8_t buf1 = 0;
	Set_BitMask(FIFOLevelReg, 0x80);
	if(Read_Reg(FIFOLevelReg)){
		return 0;
	}
	Write_Reg(FIFODataReg, buf);
	if(Read_Reg(FIFOLevelReg) != 1){
		return 0;
	}
	buf1 = Read_Reg(FIFODataReg);
	if(buf != buf1){
		return 0;
	}
	if(Read_Reg(FIFOLevelReg)){
		return 0;
	}
	Set_BitMask(FIFOLevelReg, 0x80);
#endif 
	return 1;
}

int FM175xx_Init(void) {
    FM175XX_HardReset();
    BSP_Delay_ms(10);
	if(FM175xx_Check()){
	    Write_Reg(ControlReg, 0x10); //设置为读卡器模式
	    WCI_Register(&wciFM17550);
		return 0;
	}
	return -1;
}
#else


#endif 


unsigned char Read_Ext_Reg(unsigned char reg_add) {
    Write_Reg(0x0F,0x80+reg_add);
    return Read_Reg(0x0F);
}

unsigned char Write_Ext_Reg(unsigned char reg_add,unsigned char reg_value) {
    Write_Reg(0x0F,0x40+reg_add);
    Write_Reg(0x0F,0xC0+reg_value);
    return WCI_S_OK;
}

unsigned char Set_Ext_BitMask(unsigned char reg_add,unsigned char mask) {
    unsigned char result;
    result=Write_Ext_Reg(reg_add,Read_Ext_Reg(reg_add)|mask);
    return result;
}


unsigned char Clear_Ext_BitMask(unsigned char reg_add,unsigned char mask) {
    unsigned char result;
    result=Write_Ext_Reg(reg_add,Read_Ext_Reg(reg_add)&(~mask));
    return result;
}


static CardPort fm175xxPort;

#if 0
void RC663_Init(void) {
	
	fm175xxPort.nCards = 0;
	fm175xxPort.maxCard = 1;
	fm175xxPort.typeMask = 1 << Card_T_CpuA | 1 << Card_T_CpuB | 1 << Card_T_Mifare;
	fm175xxPort.name = "RC663";
	fm175xxPort.pdata = (void*) &wciFM17550;

    RC663_HardReset();
    delay_ms(10);
//	    Rc663_WriteRegister(ControlReg, 0x10); //设置为读卡器模式
	CardPort_Register(&rc663Port, Port_Index_PICC);
}

#endif 

void FM175xx_Init(void) {
	fm175xxPort.nCards = 0;
	fm175xxPort.maxCard = 1;
	fm175xxPort.typeMask = 1 << Card_T_CpuA | 1 << Card_T_CpuB | 1 << Card_T_Mifare;
	fm175xxPort.name = "FM17550";
	fm175xxPort.pdata = (void*) &wciFM17550;
    FM175XX_HardReset();
    BSP_Delay_ms(10);
	Write_Reg(ControlReg, 0x10); //设置为读卡器模式
	WCI_Register(&wciFM17550);
	CardPort_Register(&fm175xxPort, Port_Index_PICC);
}

#include "Init.h"

INIT_ENTRY_MAIN(FM175xx_Init);


